import os
import shelve
# C:\Users\Administrator\Desktop\性能优化
# 获取绝对路径
print(os.path.abspath('./')) 

print(os.path.isabs(r'C:\Users\Administrator\Desktop\性能优化'))
print(os.path.isabs('./'))

# 获取路径信息
calcPath = r'C:\Users\Administrator\Desktop\性能优化\python\pdf_study\file.py'
print(os.path.dirname(calcPath))
print(os.path.basename(calcPath))

# 获取文件大小
print(os.path.getsize('./python/pdf_study/file.py'))

# 是否存在
print(os.path.exists('./python/pdf_study/file.py'))
print(os.path.isdir('./python/pdf_study/file.py'))
print(os.path.isfile('./python/pdf_study/file.py'))

'''
  文件读写
    纯文本文件(.txt .py .js .css .html)
    二进制文件(.doc .pdf .jpg .png) 需要自己的处理方式处理
  读写文件的3个步骤
    1，调用open()函数，返回一个File对象
    2，调用File对象的read()或write()方法
    3，调用File对象的close()方法
'''

helloFile = open('./python/pdf_study/hello.txt', 'a', encoding='utf-8')

helloFile.write('你好')

# with open('python/pachong/renren.html', 'w', encoding='utf-8') as fp:
#   fp.write(resp.read().decode('utf-8'))

# shelfFile = shelve.open('./python/pdf_study/mydata')
# cats = ['Zophie', 'Pooka', 'Simon']
# shelfFile['cats'] = cats
# shelfFile.close()

shelfFile = shelve.open('./python/pdf_study/mydata')
print(type(shelfFile))
print(shelfFile['cats'])
shelfFile.close()